package com.tsing.cedap.common.utils;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.tsing.cedap.common.config.RedisManager;
import com.tsing.cedap.common.exceptions.BusinessException;
import com.tsing.cedap.common.exceptions.CommonException;
import com.tsing.cedap.common.vo.UserVo;

public class GetLoginUserUtil {

    public static UserVo getLoginUserInfo(String token, RedisManager redisManager) {
        if (StrUtil.isBlank(token)) {
            throw new BusinessException(CommonException.Proxy.TOKEN_IS_REQUIRED);
        }
        UserVo userVo = JSONObject.parseObject(redisManager.getString(token), UserVo.class);
        if (ObjectUtil.isNull(userVo)) {
            throw new BusinessException(CommonException.Proxy.TOKEN_VERIFY_ERROR);
        }
        return userVo;
    }

}
